package stud.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import stud.aistar.entity.RegOffice;

import java.util.List;

/**
 * Created by Administrator on 2019/9/28.
 */
public interface RegOfficeMapper {
    @Select("select * from reg_office")
    List<RegOffice> findAll();

    @Select("select * from reg_office where patient_id=#{value}")
    List<RegOffice> findByPatientId(Integer pid);

    @Select("select * from reg_office where user_id=#{value}")
    List<RegOffice> findByUserId(Integer uid);


    @Select("select * from reg_office where doctor_id=#{value}")
    List<RegOffice> findByDoctorId(Integer did);

    @Select("select count(*) from reg_office where doctor_id=#{doctorId} and time_id=#{timeId}")
    Integer findCount(@Param("doctorId") Integer did, @Param("timeId") Integer tid);

    @Insert("insert into reg_office (patient_name,patient_tel,person_card,patient_age,patient_sex,patient_card" +
            ",firstdepartment_id,seconddepartments_id,doctor_id,time_id,patient_id,reg_status,create_time,reg_price,user_id)" +
            " values (#{patientName},#{patientTel},#{personCard},#{patientAge},#{patientSex},#{patientCard},#{firstdepartmentId}," +
            "#{seconddepartmentsId},#{doctorId},#{timeId},#{patientId},#{regStatus},#{createTime},#{regPrice},#{userId})")
    void saveReg(RegOffice regOffice);

    @Select("select * from reg_office where id = #{id}")
    RegOffice  findById(Integer id);


    @Update("update reg_office set reg_status=1 where id = #{id}")
    void updateStatus(Integer id);

    @Update("update reg_office set reg_status=3 where id = #{id}")
    void changeStatus(Integer id);

    @Update("update reg_office set reg_status=2 where id = #{id}")
    void forgiveStatus(Integer id);

    @Update("update reg_office set firstdepartment_id=#{firstdepartmentId},seconddepartments_id=#{seconddepartmentsId}," +
            "doctor_id=#{doctorId},time_id=#{timeId} where id=#{id}")
    void updateReg(RegOffice regOffice);

    @Select("select * from reg_office where patient_id = #{patientId} and doctor_id=#{doctorId} and time_id =#{timeId}")
    RegOffice findOne(@Param("patientId")Integer pid,@Param("doctorId")Integer did ,@Param("timeId")Integer tid);

}
